<!-- 系统自动生成 Date:2021-08-14 19:57 -->
<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="报表列表" bodyClass="gray-bg animated fadeInRight" isAnimation=false libs=["table","zTree"]/>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <@f.form id="ureport-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label> ${i18n("文件名")}：</label>
                            <@f.input name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;&nbsp;${i18n("查询")}</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i>&nbsp;${i18n("重置")}</a>
                        </li>
                    </ul>
                </div>
            </@f.form>
        </div>
        <@table id="bootstrap-table">
            <@shiro.hasPermission name="sys:ureport:del">
                <a class="btn btn-danger multiple disabled" onclick="opt.operate.delAll()"><i class="fa fa-remove"></i> ${i18n("删除")}</a>
            </@shiro.hasPermission>
            <@shiro.hasPermission name="sys:post:edit">
           	 	<a class="btn btn-success single disabled" onclick="editOpen()"><i class="fa fa-pencil-square-o"></i>&nbsp;${i18n("权限相关")}</a>
        	</@shiro.hasPermission>
        </@table>
    </div>
</div>
<div id="createShare" style="display: none;">
    <@f.form id="form-share">
        <@f.hidden name="id"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">${i18n("过期时间")}：</label>
            <div class="col-sm-8">
                <label class="radio-box"><input type="radio" id="time0" name="time" value="0" checked>永久有效</label>
                <label class="radio-box"><input type="radio" name="time" value="7" >7天</label>
                <label class="radio-box"><input type="radio" name="time" value="1" >1天</label>
            </div>
        </div>
    </@f.form>
</div>
<div id="shareInfo" style="display: none;" class="ibox-content">
    <@f.form id="form-shareInfo" class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label ">${i18n("预览链接")}：</label>
            <div class="col-sm-8">
                <@f.input name="link"/>
            </div>
        </div>
        <div class="form-group" style="padding-top: 10px">
            <label class="col-sm-3 control-label ">${i18n("访问码")}：</label>
            <div class="col-sm-3">
                <@f.input name="code"/>
            </div>
            <div class="col-sm-3">
                <button type="button" class="btn btn-sm btn-primary" onclick="copyText()"><i class="fa fa-check"></i>${i18n("复制")}</button>&nbsp;
            </div>
        </div>
    </@f.form>
    <script type="text/javascript">
        function copyText(){
            const link = $('#form-shareInfo').find('#link').val();
            const code = $('#form-shareInfo').find('#code').val();
            const info = "链接: "+link+"  密码: "+code+"\n" +
                        "--来自J2eeFAST[JU报表]的分享,请用浏览器打开链接.";
            opt.common.copy(info);
            opt.modal.msg('复制成功!');
        }
    </script>
</div>
<@footer>
<script type="text/javascript">
    var delFlag = "${permission.hasPermi("sys:ureport:del")}";
    var visible = ${permission.isPermitteds("sys:ureport:del")?string('true', 'false')};
    var prefix = baseURL + "sys/ureport";

    $(function() {
        var options = {
            url: prefix + "/list",
            delUrl: prefix + "/del",
            editUrl: prefix + "/edit/{id}",
            modalName: '<@ctx.i18n text="配置存储"/>',
            uniqueId:  'id',/* 唯一ID */
            sortName: "createTime",
            //escape: true,/* 分页设置 */
            /* clickToSelect: false, */
            //showPageGo: true,/* 分页设置 */
            //pageSize: 15,/* 分页设置 */
            //pageList: [15, 30, 50],/* 分页设置 */
            height: function(){ return $(window).height() - 100},
            columns:[
                {title: $.i18n.prop("序号"), width: 5, align: "center", formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }}
                ,{field : 'id',title : '${i18n("主键")}',visible: false}
                ,{field : 'name',title : '${i18n("文件名")}'}
                ,{field : 'remark',title : '${i18n("描述")}'}
                ,{field : 'fileName',title : '${i18n("下载文件名称")}'}
                ,{field : 'createTime',title : '${i18n("创建时间")}'}
                ,{field : 'updateTime',title : '${i18n("更新时间")}'}
                ,{title:"${i18n("操作")}",align: 'center',class:'action',visible:visible,formatter: function(value, row, index) {
                    var actions = [];
                    actions.push('<a class="" title="${i18n("预览")}" href="javascript:void(0)" onclick="opt.modal.windowOpen(\''+baseURL+'ureport/preview?_u=fast-' + row.name + '\',\''+row.name+'\')"><i class="fa fa-eye"></i>预览</a> ');
                    actions.push('<a class="" title="${i18n("分享")}" href="javascript:void(0)" onclick="createShare(\''+row.id+'\',\''+row.share+'\',\''+row.pass+'\',\''+row.code+'\',\''+row.time+'\')"><i class="fa fa-share-alt"></i> 分享</a> ');
                    actions.push('<a class="" href="javascript:void(0)" onclick="opt.modal.openTab(\''+row.name+'\',\''+baseURL+'ureport/designer?_u=fast-' + row.name + '\')" title="${i18n("报表设计")}"><i class="fa fa-pencil-square-o"></i> 设计</a> ');
                    var info = "<a  class='btn btn-default btn-xs' onclick=javascript:opt.operate.del(\'" + row.id + "\');><i class='fa fa-remove'></i> ${i18n("删除")}</a>&nbsp;";
                    info += "<a  class='btn btn-default btn-xs' onclick=javascript:editOpen(\'" + row.id +"\');><i class='fa fa-pencil-square-o'></i> ${i18n("权限设置")}</a>&nbsp;";
                    info += "<a  class='btn btn-default btn-xs' onclick=javascript:preview(\'" + row.id +"\',\'"+row.name+"\');><i class='fa fa-eye'></i> ${i18n("XML预览")}</a>";
                    info += "<a  class='btn btn-default btn-xs' onclick=javascript:copyNameCode(\'"+row.name+"\');><i class='fa fa-copy'></i> ${i18n("复制编码")}</a>";
                    actions.push('<a tabindex="0" class="" role="button" data-container="body" ' +
                        'data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" ' +
                        'data-content="'+info+'"><i class="fa fa-chevron-circle-right" title="${i18n("更多操作")}"></i>更多</a>');
                    return actions.join('');
                }}
            ]
        };
        $.table.init(options);
    });

    function editOpen(id) {
        opt.modal.open("${i18n("报表权限设置")}",opt.operate.editUrl(id),'900', '605');
    }

    function preview(id,name){
        opt.modal.windowOpen(prefix + "/previewXml/"+id,name);
    }

    function copyNameCode(name){
        name = opt.common.getName(name);
        opt.common.copy(name);
        opt.modal.msg('复制成功!');
    }

    function createShare(id,share,pass,code,time){
        const codeUrl = code;
        const password = pass;
        const uId = id;
        const sTime = time;
        if(share == 'Y'){
            if(sTime !=0 ){
                var config = {
                    url: prefix + "/getShare",
                    data: { "code": codeUrl},
                    type: "POST",
                    dataType: 'json',
                    success: function(result) {
                        if(result.code != opt.variable.web_status.SUCCESS){
                            createShare(id,"N",password,code,"1");
                        }else{
                            createShare(id,"Y",password,code,"0");
                        }
                    }
                };
                $.ajax(config);
                return;
            }
            opt.selfLayer.open({
                type: 1,
                fix: false,
                scrollbar: true,
                title: '<i class="fa fa-share-alt"></i> '+$.i18n.prop('分享链接'),
                area: ["500px", "240px"],
                shadeClose: true,
                resize: false,
                content: jQuery("#shareInfo"),
                btn: ['<i class="fa fa-check"></i> '+$.i18n.prop('取消链接'), '<i class="fa fa-close"></i> '+ $.i18n.prop('取消')],
                success: function(layero, index){
                    var link = layero.find('#link');
                    var code = layero.find('#code');
                    link.val(basePath + '/ureport/shareview?__surl=' +codeUrl);
                    code.val(password);
                },
                btn1: function (index) {
                    opt.operate.post(prefix + "/cancelShare", { "code": codeUrl},function(){
                        opt.selfLayer.close(index);
                    });
                }
            })
        }else{
            opt.selfLayer.open({
                type: 1,
                fix: false,
                scrollbar: false,
                title: '<i class="fa fa-share-alt"></i> '+$.i18n.prop('创建分享连接'),
                area: ["500px", "150px"],
                shadeClose: true,
                resize: false,
                content: jQuery("#createShare"),
                btn: ['<i class="fa fa-check"></i> '+$.i18n.prop('确定'), '<i class="fa fa-close"></i> '+ $.i18n.prop('取消')],
                success: function(layero, index){
                    layero.find('#id').val(uId);
                    layero.find('#time0').attr('checked', true);
                },
                btn1: function (index,layero) {
                    var data = layero.find('#form-share').serialize();
                    opt.operate.post(prefix + "/createShare",data ,function(ref){
                        opt.selfLayer.close(index);
                        createShare(uId,"Y",ref.pass,ref.__surl,ref.time);
                    });
                }
            })
        }
    }
</script>
</@footer>
</@pageTheme>